package com.voxel.sense.infomsg.module.map.monitor.baseInfo;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.example.com.common.view.recycler.RecyclerAdapter;
import com.voxel.sense.infomsg.R;
import com.voxel.sense.infomsg.data.bean.ConditionBean;
import com.voxel.sense.infomsg.view.decoration.ItemDivider;
import com.voxel.sense.infomsg.view.decoration.LinearItemDecoration;
import com.voxel.sense.infomsg.widget.adapter.AbsPickRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

import cyy.example.com.facotry.Factory;
import cyy.example.com.facotry.constants.Constants;

/**
 * Created by chenyiyao on 2017/10/31.
 */

public class PopWindowStaffMenu extends PopupWindow {
    private View rootView;
    private List<String> mDataList = new ArrayList<>();
    private Context mContext;
    private RecyclerView recycle_view;
    private RecyclerAdapter.AdapterListener mItemListener;
    private AbsPickRecyclerAdapter mAdapter;

    public PopWindowStaffMenu(Context context) {
        mContext = context;
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rootView = inflater.inflate(R.layout.item_popwindow_recycler_menu, null);
        recycle_view = rootView.findViewById(R.id.recycle_view);

//        //设置SelectPicPopupWindow的视图
        setContentView(rootView);

//        //设置SelectPicPopupWindow弹出窗体的宽
        setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
//        //设置SelectPicPopupWindow弹出窗体的高
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        initMenu();
    }

    public void setData(List<String> list) {
        mDataList.clear();
        mDataList.addAll(list);
    }

    public boolean initMenu() {
        recycle_view.setLayoutManager(new LinearLayoutManager(Factory.app()));
        recycle_view.addItemDecoration(new LinearItemDecoration(R.drawable.recycle_divider));
        mAdapter = new MapStaffMenuRecycAdapter(new RecyclerAdapter.AdapterListener<ConditionBean>() {
            @Override
            public void onItemClick(RecyclerAdapter.ViewHolder holder, ConditionBean conditionBean) {
                if (mItemListener != null) {
                    mItemListener.onItemClick(holder,conditionBean);
                }
            }

            @Override
            public void onItemLongClick(RecyclerAdapter.ViewHolder holder, ConditionBean conditionBean) {
                if (mItemListener != null) {
                    mItemListener.onItemLongClick(holder,conditionBean);
                }
            }
        });
        mAdapter.replace(initData());
        recycle_view.setAdapter(mAdapter);
        return false;
    }

    private List<ConditionBean> initData() {
        ConditionBean bean1 = new ConditionBean(Constants.MARKER_TYPE_PEOPLE, "7", "执法人员", true);
        ConditionBean bean2 = new ConditionBean(Constants.MARKER_TYPE_PEOPLE, "6", "运维人员", true);
        ConditionBean bean3 = new ConditionBean(Constants.MARKER_TYPE_PEOPLE, "5", "巡查人员", true);

        List<ConditionBean> beanList = new ArrayList<>();
        beanList.add(bean1);
        beanList.add(bean2);
        beanList.add(bean3);
        return beanList;
    }



    public void setItemListener(RecyclerAdapter.AdapterListener itemListener) {
        mItemListener = itemListener;
    }
}
